package com.ljf.utility.domain.validator;

import com.ljf.common.domain.validator.NoDbBasisValidator;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.utils.CollectionUtil;
import com.ljf.utility.dto.other.CalculateMath;
import org.springframework.stereotype.Component;

/**
 * 计算器  业务校验
 *
 * @author LJF
 * @since 2024-08-11
 */
@Component
public class CalculateValidator extends NoDbBasisValidator {

    /**
     * 数学计算器接口  业务校验
     *
     * @param model
     * @throws ServiceException
     */
    public void checkMathCalculator(CalculateMath model) throws ServiceException {
        if (CollectionUtil.isEmpty(model.getEquationList())) {
            throw new ServiceException("计算异常:请输入公式");
        }
        if (model.getDecimalPlaces() == null) {
            throw new ServiceException("计算异常:请输入小数位数");
        }
        if (model.getDecimalPlaces() < 0) {
            throw new ServiceException("计算异常:小数位数不能为负数");
        }
    }

}
